﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Web.Script.Services;
using CoyoEden.Web.Controls;
using CoyoEden.Web.Data;
using System.Web.Services;
using CoyoEden.Web.Controller;
using Vivasky.Core.Infrastructure;

namespace CoyoEden.Web.Services
{
	[ScriptService]
	public class Vote:WebService
	{
		#region Flexigrid
		[WebMethod]
		public FlexigridData<Models.Vote> GetVotes(FlexiGridInputData Params)
		{
		
			var c = Models.Vote.Votes.OrderByDescending(item => item.DateCreated).AsQueryable();
			var data = new FlexigridData<Models.Vote>(c.AsEnumerable(), Params);
			return data;
		}
		#endregion

		#region Methods
		[WebMethod]
		public FeedbackData PreEdit(Dictionary<string, string> Params)
		{

			FeedbackData retVal = new FeedbackData();
			Models.Vote tempObj = VoteController.Single(Params, out retVal);
			if (tempObj != null)
			{
				//1,render VoteItemList
				ViewManager<VoteViewBase> vm = new ViewManager<VoteViewBase>("~/Views/VoteDetailVoteItemList.ascx");
				vm.Control.VoteItemsShow = tempObj.VoteItems;
				String voteItemsHtml = vm.Render();
				//2,render the whole Vote
				vm = new ViewManager<VoteViewBase>("~/Views/VoteDetail.ascx");
				vm.Control.TheVote = tempObj;
				vm.Control.VoteItemsShowHtml = voteItemsHtml;
				retVal.Body = vm.Render();
			}
			return retVal;
		}
		[WebMethod]
		public FeedbackData Update(List<NameValuePair<string, string>> Params)
		{
			FeedbackData retVal = new FeedbackData();
			VoteController.Update(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData Delete(Dictionary<string, string> Params)
		{
			FeedbackData retVal = new FeedbackData();
			VoteController.Delete(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SelectPosts(Dictionary<string, string> Params)
		{
			FeedbackData retVal = new FeedbackData();
			VoteController.SelectPosts(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData AddVoteItems(List<NameValuePair<string, string>> Params) {
			FeedbackData retVal = new FeedbackData();
			VoteController.AddVoteItems(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData DelVoteItem(Dictionary<string,string> Params) {
			FeedbackData retVal = new FeedbackData();
			VoteController.DelVoteItem(Params,out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SelectVotes(Dictionary<string,string> Params) {
			FeedbackData retVal = new FeedbackData();
			VoteController.SelectVotes(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData ShowVoteItems(Dictionary<string,string> Params) {
			FeedbackData retVal = new FeedbackData();
			VoteController.ShowVoteItems(Params,out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData DoVote(List<NameValuePair<string, string>> Params)
		{
			FeedbackData retVal = new FeedbackData();
			VoteController.DoVote(Params, out retVal);
			return retVal;
		}
		#endregion
	}
}
